<?php
ob_start(); //Khởi tạo buffer
session_start();
$checkAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
require 'user_access.php';
if(isset($_POST['user']) and is_array($_POST['user']) and !empty($_POST['user'])) //Kiểm tra hành động login
{
    $user = $_POST['user'];
    require_once '../helpers/database.php';
    if(auth_login($user['uname'], $user['pword']) == TRUE)
    {
        $_SESSION['AUTH'] = TRUE;
    }
}
?>
<?php if($checkAjax): ?>
<?php
    require_once '../helpers/database.php';                
    require $_GET['com'] . '/controller.php';
    mysqli_close(getDB());
?>
<?php else: ?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Adminstrator</title>
        <link rel="stylesheet" href="../views/css/bootstrap.min.css" type="text/css" />
        <link rel="stylesheet" href="style.css" type="text/css" />
        <script type="text/javascript" src="../views/js/jquery.js"></script>
        <script type="text/javascript" src="../views/js/bootstrap.min.js"></script>
        <!-- Place inside the <head> of your HTML -->
        <script type="text/javascript" src="../tinymce/tinymce.min.js"></script>       
        <script type="text/javascript" src="script.js"></script>
    </head>
    <body>
        <div id="wrapper">
            <div class="container">
                <div id="header">
<div style="position: static;" class="navbar navbar-inverse">
              <div class="navbar-inner">
                <div class="container">
                  <a data-target=".navbar-inverse-collapse" data-toggle="collapse" class="btn btn-navbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                  </a>
                  <a href="<?php echo "http://" . $_SERVER['HTTP_HOST'] . '/travel-network/admin' ?>" class="brand">Dashboard</a>
                  <div class="nav-collapse collapse navbar-inverse-collapse">
                    <ul class="nav">
                      <li class="active"><a href="#">Site</a></li>
                      <li><a href="?com=user&view=list">User</a></li>
                      <li class="dropdown">
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">Content <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                          <li><a href="?com=content&action=entry&view=list">Entry</a></li>
                          <li><a href="#">Comment</a></li>
                          <li><a href="#">Vote</a></li>
                        </ul>
                      </li>
                      <li><a href="#">Statistics</a></li>
                    </ul>
                  </div><!-- /.nav-collapse -->
                </div>
              </div><!-- /navbar-inner -->
            </div>
                </div> <!-- End header -->
                <div class="toolbar">
                    
                    <ul class="nav nav-pills">
                        <!--<li><a href="#" title="Create new account" ><img src="images/icon_new.png" /></a></li> -->
                        <!-- <li><a href="#" title="Save" ><img src="images/icon_save.png" /></a></li> -->
                        <li><a href="#" title="Change user status"><img src="images/icon_active.png" /></a></li>                        
                        <li><a href="#" title="Delete selected users" onclick="deleteSelectedItems()"><img src="images/icon_delete.png" /></a></li>
                    </ul>
                </div>
                <div id="message">
                    <button data-dismiss="alert" type="button" class="close">&times;</button>
                    <div id="msg">
                        
                    </div>
                </div>
                <?php
                if(auth_user() !== TRUE) //Xác thực đã đăng nhập
                {
                    include 'login.php';
                }
                else
                {
                    ?>
                <div id="content" class="block">
                    <?php
                    require_once '../helpers/database.php';
                    if(!isset($_GET['com'])) $_GET['com'] = 'site';                
                    require $_GET['com'] . '/controller.php';
                    mysqli_close(getDB());
                    ?>
                </div>                
                    <?php
                }
                ?>   


            </div>
        </div>
    </body>
</html>
<?php
        ob_flush(); //Gửi buffer
        ob_clean(); //Xóa buffer
?>
<?php endif; ?>